package com.fizzkai.p2p.website.controller;

import com.fizzkai.p2p.bussness.domain.ExpAccount;
import com.fizzkai.p2p.bussness.service.IExpAccountService;
import com.fizzkai.p2p.core.domain.Account;
import com.fizzkai.p2p.core.domain.LoginInfo;
import com.fizzkai.p2p.core.service.IAccountService;
import com.fizzkai.p2p.core.util.UserContext;
import com.fizzkai.p2p.website.util.RequireLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PersonalController {
    @Autowired
    private IAccountService accountService;
    @Autowired
    private IExpAccountService expAccountService;


    /**
     * 个人中心 界面
     * @param model
     * @return
     */
    @RequestMapping("/personal")
    @RequireLogin
    public String personal(Model model){
        LoginInfo loginInfo = UserContext.getCurrentLoginInfo();
        if (loginInfo == null) {
            return "personal";
        }
        Account account = accountService.get(loginInfo.getId());
        ExpAccount expAccount = expAccountService.get(loginInfo.getId());
        model.addAttribute("loginInfo", loginInfo);
        model.addAttribute("account", account);
        model.addAttribute("expAccount", expAccount);
        return "personal";
    }
}
